from datetime import datetime
import logging
import time



date_format = "%Y-%m-%d %H:%M:%S"

def str_2_millisecond(date_str):
    return  int(datetime.strptime(date_str, date_format).timestamp() * 1000)

def millisecond_2_date_str(millisecond):
    return datetime.fromtimestamp(millisecond/1000)



def getLogger(logger_name):
    global logger
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    filename = logger_name+'-' + str(millisecond_2_date_str(time.time()*1000))+'.log'
    # 创建一个文件处理程序，设置 mode='w' 以复写日志文件
    file_handler = logging.FileHandler(filename, mode='w')
    file_handler.setLevel(logging.INFO)

    # 设置日志格式
    formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    file_handler.setFormatter(formatter)

    # 将文件处理程序添加到日志记录器
    logger.addHandler(file_handler)
    return logger

logger = None

if __name__ == "__main__":
    print(millisecond_2_date_str(1734313632767))
